package com.jingding.procurement.util;

import com.jingding.procurement.enumeration.EntityEnum;
import com.jingding.procurement.pojo.entity.*;

import java.io.*;

public class IO {

    //传入entity对象修改启用状态或时间
    public static void write(Entity entity) throws IOException {

        FileOutputStream fos = new FileOutputStream("Entity.txt");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(entity);
        oos.close();
    }

    //调用方法读取entity文档数据
    public static Entity read() throws IOException, ClassNotFoundException {
        FileInputStream fis = new FileInputStream("Entity.txt");
        ObjectInputStream ois = new ObjectInputStream(fis);
        return (Entity) ois.readObject();
    }



    //读取供方检验单文档数据
    public static SupplierInspectionSheetEntity supplierInspectionSheetRead() throws IOException, ClassNotFoundException {
        FileInputStream fis = new FileInputStream("supplierInspectionSheetEntity.txt");
        ObjectInputStream ois = new ObjectInputStream(fis);
        return (SupplierInspectionSheetEntity) ois.readObject();
    }
    //传入供方检验单对象修改启用状态或时间
    public static void supplierInspectionSheetWrite(SupplierInspectionSheetEntity supplierInspectionSheetEntity) throws IOException {
        FileOutputStream fos = new FileOutputStream("supplierInspectionSheetEntity.txt");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(supplierInspectionSheetEntity);
        oos.close();
    }


    //读取采购合同文档数据
    public static ProcurementContractEntity procurementContractRead() throws IOException, ClassNotFoundException {
        FileInputStream fis = new FileInputStream("procurementContractEntity.txt");
        ObjectInputStream ois = new ObjectInputStream(fis);
        return (ProcurementContractEntity) ois.readObject();
    }
    //传入采购合同对象修改启用状态或时间
    public static void procurementContractWrite(ProcurementContractEntity procurementContractEntity) throws IOException {

        FileOutputStream fos = new FileOutputStream("procurementContractEntity.txt");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(procurementContractEntity);
        oos.close();
    }


    //读取采购订单文档数据
    public static PurchaseOrdersEntity purchaseOrdersRead() throws IOException, ClassNotFoundException {
        FileInputStream fis = new FileInputStream("purchaseOrdersEntity.txt");
        ObjectInputStream ois = new ObjectInputStream(fis);
        return (PurchaseOrdersEntity) ois.readObject();
    }
    //传入采购订单对象修改启用状态或时间
    public static void purchaseOrdersWrite(PurchaseOrdersEntity purchaseOrdersEntity) throws IOException {
        FileOutputStream fos = new FileOutputStream("purchaseOrdersEntity.txt");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(purchaseOrdersEntity);
        oos.close();
    }

    //读取采购磅单文档数据
    public static PurchasePoundsEntity purchasePoundsRead() throws IOException, ClassNotFoundException {
        FileInputStream fis = new FileInputStream("purchasePoundsEntity.txt");
        ObjectInputStream ois = new ObjectInputStream(fis);
        return (PurchasePoundsEntity) ois.readObject();
    }
    //传入采购磅单对象修改启用状态或时间
    public static void purchasePoundsWrite(PurchasePoundsEntity purchasePoundsEntity) throws IOException {
        FileOutputStream fos = new FileOutputStream("purchasePoundsEntity.txt");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(purchasePoundsEntity);
        oos.close();
    }

    //读取销售出库文档数据
    public static SellOutEntity sellOutRead() throws IOException, ClassNotFoundException {
        FileInputStream fis = new FileInputStream("sellOutEntity.txt");
        ObjectInputStream ois = new ObjectInputStream(fis);
        return (SellOutEntity) ois.readObject();
    }
    //传入销售出库对象修改启用状态或时间
    public static void sellOutWrite(SellOutEntity sellOutEntity) throws IOException {
        FileOutputStream fos = new FileOutputStream("sellOutEntity.txt");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(sellOutEntity);
        oos.close();
    }

    //读取扣吨计算单文档数据
    public static TonnageEntity tonnageRead() throws IOException, ClassNotFoundException {
        FileInputStream fis = new FileInputStream("tonnageEntity.txt");
        ObjectInputStream ois = new ObjectInputStream(fis);
        return (TonnageEntity) ois.readObject();
    }
    //传入扣吨计算单对象修改启用状态或时间
    public static void tonnageWrite(TonnageEntity tonnageEntity) throws IOException {
        FileOutputStream fos = new FileOutputStream("tonnageEntity.txt");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(tonnageEntity);
        oos.close();
    }


}
